<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />
</head>

<body>
    <header class="aui-bar aui-bar-nav main-header">
        <a class="aui-pull-left aui-btn" tapmode onclick="closeWin();">
            <span class="aui-iconfont aui-icon-left"></span>
        </a>
        <div class="aui-title" id="title">
            检测记录创建/选择
        </div>
    </header>
    <div class="aui-bar aui-bar-nav sub-header"></div>
    <div class="aui-content aui-margin-b-15" style="margin-top:50px;padding-bottom: 50px;">
        <div class="white_background">
            <ul class="aui-list aui-form-list">
                <li class="aui-list-item">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label" style="width:150px">创建日期</div>
                        <div class="aui-list-item-input" onclick="timePicker();">
                            <input type="text" placeholder="选择日期" class="aui-input" id="dateTime">
                        </div>
                    </div>
                </li>
                <li class="aui-list-item">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label" style="width:150px">产线</div>
                        <div class="aui-list-item-input">
                            <input type="text" placeholder="请选择产线" id="workCenterCode" value=""
                                onclick="getIdSelector();" />
                        </div>
                        <i class="aui-input-addon aui-iconfont aui-icon-right" onclick="goSelectWorkCenterLine()"></i>
                    </div>
                </li>
                <li class="aui-list-item">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label" style="width:150px">规格</div>
                        <div class="aui-list-item-input">
                            <input type="text" placeholder="请输入规格" id="drawing" value="">
                        </div>
                    </div>
                </li>
            </ul>
            <div style="padding-top:2%;"></div>
            <div class="aui-btn aui-btn-info aui-btn-block" onclick="search()">查询</div>
        </div>
        <ul class="ui-selectee" id="tbodyHtml">

        </ul>

    </div>
    <footer class="aui-bar aui-bar-tab" id="footer">
        <div class="aui-btn aui-btn-info aui-btn-block" style="margin:0 5%;width: 90%;" onclick="goPageWorkOrder()">
            创建检测记录单</div>

    </footer>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="../script/public.js"></script>
<script type="text/javascript">
    //光标所在id
    var idSelector = "";

    var workCenterGid = ""; //产线GID
    var workCenterCode = ""; //产线编码
    var workCenterName = ""; //产线名称


    var list = [];
    var arrSave = [];//要带回的单据号

    let currentDate = new Date();
    let year = currentDate.getFullYear(); // 获取当前年份
    let month = (currentDate.getMonth() + 1) < 10 ? "0" + (currentDate.getMonth() + 1) : (currentDate.getMonth() + 1); // 获取当前月份，注意月份从0开始，所以要加1
    let day = currentDate.getDate() < 10 ? "0" + currentDate.getDate() : currentDate.getDate(); // 获取当前日期
    let time = year + '-' + month + '-' + day

    //初始化查询
    apiready = function () {
        $("#dateTime").val(time);
        search();
    }

    // 获取光标所在组件的id
    function getIdSelector() {
        var e = event || window.event;
        var el = e.srcElement || e.target;
        idSelector = el.id;
        $("#" + el.id).select();
    }

    //时间选择器
    function timePicker() {
        api.openPicker({
            type: 'date',
            date: new Date(),
            title: '选择日期'
        }, function (ret, err) {
            if (ret) {
                var monthTemp = (ret.month < 10 ? '0' + ret.month : ret.month);
                var dayTemp = (ret.day < 10 ? '0' + ret.day : ret.day);
                var date = ret.year + "-" + monthTemp + "-" + dayTemp;
                $("#dateTime").val(date);
            }
        });
    }



    //选中产线
    function goSelectWorkCenterLine() {
        api.openWin({
            name: 'usmSelectLine',
            url: 'usmSelectLine.html',
            pageParam: {
                flag: "in",
                name: "qcmChkBillCreateacNew",
                mrlCode: "",
                lotCode: "",
                qty: ""
            }
        });
    }
    //产线选择后回调函数
    function setLineCode(id, code, name) {
        workCenterGid = id;
        workCenterCode = code;
        workCenterName = name;
        document.getElementById('workCenterCode').value = code + ":" + name;
    }

    function search() {
        var dateTime = $("#dateTime").val();
        var drawing = $("#drawing").val();
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/searchChkRecord";
        var data = {
            values: { ////以表单方式提交参数（JSON对象）
                workCenterCode: workCenterCode,
                un: un,
                drawing: drawing,
                createDate: dateTime
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                //成功
                if (myobj.code == '0') {
                    list = myobj.list;
                    setTable(list)
                } else {
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });

                }
            }
        });
    }


    function setTable(list) {
        var html = "";
        for (var i = 0; i < list.length; i++) {

            html += "<li class='sortable ui-selectee ui-sortable' >";
            html += "<div class='white_background'>"
            html += "<ul class='aui-list aui-media-list ui-selectee'>";
            html += "<li class='aui-list-item  ui-selectee' style='color: black !important;background-color: #addbef !important;'>";
            html += "<div class='aui-media-list-item-inner ui-selectee ' >";
            html += "<div class='aui-list-item-inner ui-selectee '   onclick='goPage(\"" + list[i].recordCode + "\");'>";
            html += "<div class='aui-list-item-text ui-selectee' style='height: 25px;'>";
            html += "<div class='aui-list-item-label ui-selectee list-tr-title '>记录单号:</div>";
            html += "<div class='aui-list-item-inner ui-selectee '>" + list[i].recordCode + "</div>";
            html += "</div>";
            html += "<div class='aui-list-item-text ui-selectee' style='height: 25px;'>";
            html += "<div class='aui-list-item-label ui-selectee list-tr-title'>产线编码:</div>";
            html += "<div class='aui-list-item-inner ui-selectee'>" + list[i].workCenterCode + "</div>";
            html += "</div>";
            html += "<div class='aui-list-item-text ui-selectee' style='height: 25px;'>";
            html += "<div class='aui-list-item-label ui-selectee list-tr-title'>产线名称:</div>";
            html += "<div class='aui-list-item-inner ui-selectee'>" + list[i].workCenterName + "</div>";
            html += "</div>";
            html += "<div class='aui-list-item-text ui-selectee' style='height: 25px;'>";
            html += "<div class='aui-list-item-label ui-selectee list-tr-title'>工单号:</div>";
            html += "<div class='aui-list-item-inner ui-selectee'>" + list[i].workOrderCode + "</div>";
            html += "</div>";
            //html += "<div class='aui-list-item-text ui-selectee'>";
            html += "<div class='aui-list-item-text ui-selectee' style='height: 25px;'>";
            html += "<div class='aui-list-item-label ui-selectee list-tr-title'>物料编码:</div>";
            html += "<div class='aui-list-item-inner ui-selectee' style = 'word-wrap:break-word; overflow:hidden;'>" + list[i].mrlCode + "</div>";
            html += "</div>";
            html += "<div class='aui-list-item-text ui-selectee' style='height: 25px;'>";
            html += "<div class='aui-list-item-label ui-selectee list-tr-title'>规格:</div>";
            html += "<div class='aui-list-item-inner ui-selectee' style = 'word-wrap:break-word; overflow:hidden;'>" + list[i].drawing + "</div>";
            html += "</div>";
            html += "<div class='aui-list-item-text ui-selectee' style='height: 25px;'>";
            html += "<div class='aui-list-item-label ui-selectee list-tr-title'>物料名称:</div>";
            html += "<div class='aui-list-item-inner ui-selectee' style = 'word-wrap:break-word; overflow:hidden;'>" + list[i].mrlName + "</div>";
            html += "</div>";
            html += "<div class='aui-list-item-text ui-selectee' style='height: 25px;'>";
            html += "<div class='aui-list-item-label ui-selectee list-tr-title'>创建时间:</div>";
            html += "<div class='aui-list-item-inner ui-selectee' style = 'word-wrap:break-word; overflow:hidden;'>" + list[i].create_date + "</div>";
            html += "</div>";
            html += "<div class='aui-list-item-text ui-selectee' style='height: 25px;'>";
            html += "<div class='aui-list-item-label ui-selectee list-tr-title'>检测单数量:</div>";
            html += "<div class='aui-list-item-inner ui-selectee' style = 'word-wrap:break-word; overflow:hidden;'>" + list[i].qty + "</div>";
            html += "</div>";

            html += "</div>";
            html += "</div>";
            html += "</li>";
            html += "</ul>";
            html += "</div>";
            html += "</li>";
        }
        $api.html($api.byId("tbodyHtml"), html);
    };



    function goPage(code) {
        api.openWin({
            name: 'qcmChkBillCreateOrDeal',
            url: 'qcmChkBillCreateOrDeal.html',
            pageParam: {
                name: "qcmChkBillCreateacNew",
                recordCode: code,
            }

        });
    }
    //创建检测记录单
    function goPageWorkOrder() {
        api.openWin({
            name: 'qcmChkCreateRecord',
            url: 'qcmChkCreateRecord.html',
            pageParam: {
                name: "qcmChkBillCreateacNew"
            }
        });
    }

    //返回按钮
    function closeWin() {
        api.closeWin({});
    }

</script>


</html>